package com.spring.service.impl;


import com.spring.annotation.Autowired;
import com.spring.annotation.Service;
import com.spring.annotation.Transactional;
import com.spring.dao.AccountDao;
import com.spring.pojo.Account;
import com.spring.service.TransferService;



/**
 * @author 应癫
 */
@Service
public class TransferServiceImpl implements TransferService {



    @Autowired
    private AccountDao accountDao;


    @Override
    @Transactional
    public void transfer(String fromCardNo, String toCardNo, int money) throws Exception {



        Account from = accountDao.queryAccountByCardNo(fromCardNo);
        Account to = accountDao.queryAccountByCardNo(toCardNo);

        from.setMoney(from.getMoney()-money);
        to.setMoney(to.getMoney()+money);

        accountDao.updateAccountByCardNo(to);
        int c = 1/0;
        accountDao.updateAccountByCardNo(from);



    }
}
